<template>
  <el-upload
    action="#"
    list-type="picture-card"
    :show-file-list="false"
    :http-request="uploadFile"
    accept=".JPG, .png, .jpeg"
    multiple="multiple"
  >
    <el-image
      v-if="valueUrl"
      style="width: 100%; height: 100%"
      :src="valueUrl"
    ></el-image>
    <i v-else class="el-icon-plus"></i>
  </el-upload>
</template>

<script>
import axios from "axios";
export default {
  props: ["url", "isoppositeinfer", "image_type"],
  computed: {
    isStore_id() {
      return this.$store.state.user.store_id;
    },
  },
  data() {
    return {
      valueUrl: null,
    };
  },
  methods: {
    uploadFile(file) {
      let files = file.file;
      // 
      this.https("/image_save_api", {
        id_number: this.isStore_id,
        event: "business_license",
        image_type: this.image_type,
        image: files,
      }).then((res) => {
        this.valueUrl = res.db_save_dir;
        const formData = new FormData();
        formData.append('image',files)
        if(this.isoppositeinfer){
            formData.append('isoppositeinfer',this.isoppositeinfer)
        }
        this.$emit('changedata',Object.assign(res))
        axios.post(`http://xscab4.natappfree.cc/${this.url}`,formData).then((res1) => {
          this.$emit('changedata',Object.assign(res1.data.result,res[1]))
        }).catch((err) => {
            this.$emit('changedata',Object.assign(res[1]))

            console.log('@@@@')
      });
     
      })
      // if(this.isoppositeinfer){
      //   formData.append("isoppositeinfer", this.isoppositeinfer); // 其他需要传递的键值对
      // }
      // request
      //   .post(`${this.url}`, formData)
      //   .then((res) => {
      //       this.$emit('changedata',{result:res.result,file:file.file })
      //   });
      //   let _this =this
      //   const reader = new FileReader(); // 创建读取文件对象
      //   reader.readAsDataURL(files); // 发起异步请求，读取文件
      //   reader.onload = function () {
      //     // 文件读取完成后
      //     // 读取完成后，将结果赋值给img的src
      //     _this.valueUrl = this.result;
      //     _this.$emit("changedata", { file: file.file });

      //   };
    },
  },
};
</script>

<style lang="scss" scoped></style>
